<?php
/**
 * Fend Framework
**/
class Fend_Cache
{
    /**
     * 文件cache
     */
    const CACHE_TYPE_FILE = 0;

    /**
     * redis cache
     */
    const CACHE_TYPE_REDIS = 1;

    /**
     * Swoole Table
     */
    const CACHE_TYPE_SWOOLE_TABLE = 2;

    /**
     * Memcache
     */
    const CACHE_TYPE_MEMCACHE = 3;

    private static $in=null;
    /**
     * @param int $t    选择数据0-文件,1-Redis,2-swoole-table
     * @param int $db   选择数据库
     *
     * @return Fend_Cache_Fcache|Fend_Cache_Redis|null
     */
    public static function factory($t=self::CACHE_TYPE_FILE,$db=0)
    {
        if($t== self::CACHE_TYPE_REDIS){
            self::$in=Fend_Cache_Redis::Factory(!empty($db)?$db:'default');
        }elseif($t == self::CACHE_TYPE_SWOOLE_TABLE){
            self::$in=Fend_Cache_Swooletable::Factory();
        } elseif ($t == self::CACHE_TYPE_MEMCACHE) {
            return Fend_Cache_Memcache::Factory($db);
        }elseif($t == self::CACHE_TYPE_FILE) {
            self::$in=Fend_Cache_Fcache::Factory();
        }else{
            throw new Exception("错误的fend_cache类型",-221);
        }
        return self::$in;
    }
}
